<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="解约合同编号" prop="sfContractNo">
        <el-input
          v-model="queryParams.sfContractNo"
          placeholder="请输入解约合同编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="小区名" prop="premiseName">
        <el-input
          v-model="queryParams.premiseName"
          placeholder="请输入小区名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="解约日期" prop="leaseStartTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.leaseStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择解约时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核日期" prop="leaseEndTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.leaseEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="解约合同编号" align="center" prop="sfContractNo" />
      <el-table-column label="小区" align="center" prop="premiseName" />
      <!--租约期限开始时间-->
      <el-table-column label="解约时间" align="center" prop="leaseStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaseStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--租约期限结束时间-->
      <el-table-column label="审核时间" align="center" prop="leaseEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaseEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结算金额" align="center" prop="depositMoney" />
      <el-table-column label="操作人" align="center" prop="sfUserName" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="合同编号" prop="sfContractNo">
          <el-input v-model="form.sfContractNo" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="外部合同编号" prop="outContractNo">
          <el-input v-model="form.outContractNo" placeholder="请输入外部合同编号" />
        </el-form-item>
        <el-form-item label="上一合同ID，续约合同的时候" prop="lastContractId">
          <el-input v-model="form.lastContractId" placeholder="请输入上一合同ID，续约合同的时候" />
        </el-form-item>
        <el-form-item label="上一合同编号" prop="lastContractNo">
          <el-input v-model="form.lastContractNo" placeholder="请输入上一合同编号" />
        </el-form-item>
        <el-form-item label="商户ID" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入商户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="部门编号" prop="deptNo">
          <el-input v-model="form.deptNo" placeholder="请输入部门编号" />
        </el-form-item>
        <el-form-item label="小区名(使用楼盘名称)" prop="premiseName">
          <el-input v-model="form.premiseName" placeholder="请输入小区名(使用楼盘名称)" />
        </el-form-item>
        <el-form-item label="房产编号" prop="houseId">
          <el-input v-model="form.houseId" placeholder="请输入房产编号" />
        </el-form-item>
        <el-form-item label="房产信息(考虑在房产表中增加house_name，然后带出)" prop="houseName">
          <el-input v-model="form.houseName" placeholder="请输入房产信息(考虑在房产表中增加house_name，然后带出)" />
        </el-form-item>
        <el-form-item label="所有权类型(1：国有房产，2：直管房产，3：自管房产，4：军队房产，5：集体所有房产，6：私有(自由)房产，7：港、澳、台投资房产，8：涉外房产，9：其它房产)" prop="houseType">
          <el-select v-model="form.houseType" placeholder="请选择所有权类型(1：国有房产，2：直管房产，3：自管房产，4：军队房产，5：集体所有房产，6：私有(自由)房产，7：港、澳、台投资房产，8：涉外房产，9：其它房产)">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="房产证书编号" prop="houseZsNo">
          <el-input v-model="form.houseZsNo" placeholder="请输入房产证书编号" />
        </el-form-item>
        <el-form-item label="产权地址" prop="cqAddress">
          <el-input v-model="form.cqAddress" placeholder="请输入产权地址" />
        </el-form-item>
        <el-form-item label="业主ID" prop="ownerId">
          <el-input v-model="form.ownerId" placeholder="请输入业主ID" />
        </el-form-item>
        <el-form-item label="业主姓名" prop="ownerName">
          <el-input v-model="form.ownerName" placeholder="请输入业主姓名" />
        </el-form-item>
        <el-form-item label="是否为签约人" prop="signWithOwner">
          <el-input v-model="form.signWithOwner" placeholder="请输入是否为签约人" />
        </el-form-item>
        <el-form-item label="业主证件号码" prop="ownerIdCard">
          <el-input v-model="form.ownerIdCard" placeholder="请输入业主证件号码" />
        </el-form-item>
        <el-form-item label="业主手机号" prop="ownerMobile">
          <el-input v-model="form.ownerMobile" placeholder="请输入业主手机号" />
        </el-form-item>
        <el-form-item label="业主联系地址" prop="ownerContactAddress">
          <el-input v-model="form.ownerContactAddress" placeholder="请输入业主联系地址" />
        </el-form-item>
        <el-form-item label="签约人(甲方)" prop="signUserName">
          <el-input v-model="form.signUserName" placeholder="请输入签约人(甲方)" />
        </el-form-item>
        <el-form-item label="签约人证件号" prop="signUserIdCard">
          <el-input v-model="form.signUserIdCard" placeholder="请输入签约人证件号" />
        </el-form-item>
        <el-form-item label="签约人手机号" prop="signUserMobile">
          <el-input v-model="form.signUserMobile" placeholder="请输入签约人手机号" />
        </el-form-item>
        <el-form-item label="紧急联系电话" prop="signUserEmergencyPhone">
          <el-input v-model="form.signUserEmergencyPhone" placeholder="请输入紧急联系电话" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCard">
          <el-input v-model="form.bankCard" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="持卡人姓名" prop="bankUserName">
          <el-input v-model="form.bankUserName" placeholder="请输入持卡人姓名" />
        </el-form-item>
        <el-form-item label="持卡人身份证" prop="bankUserIdCard">
          <el-input v-model="form.bankUserIdCard" placeholder="请输入持卡人身份证" />
        </el-form-item>
        <el-form-item label="银行ID" prop="bankId">
          <el-input v-model="form.bankId" placeholder="请输入银行ID" />
        </el-form-item>
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称" />
        </el-form-item>
        <el-form-item label="开户行(支行)" prop="bankOpen">
          <el-input v-model="form.bankOpen" placeholder="请输入开户行(支行)" />
        </el-form-item>
        <el-form-item label="租约期限开始时间" prop="leaseStartTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.leaseStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择租约期限开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="租约期限结束时间" prop="leaseEndTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.leaseEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择租约期限结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="收房月租金" prop="monthRent">
          <el-input v-model="form.monthRent" placeholder="请输入收房月租金" />
        </el-form-item>
        <el-form-item label="房产押金" prop="depositMoney">
          <el-input v-model="form.depositMoney" placeholder="请输入房产押金" />
        </el-form-item>
        <el-form-item label="支付方式(押X付Y的X)" prop="depositType">
          <el-select v-model="form.depositType" placeholder="请选择支付方式(押X付Y的X)">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="支付方式(押X付Y的Y）" prop="paymentType">
          <el-select v-model="form.paymentType" placeholder="请选择支付方式(押X付Y的Y）">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="合同签订时间，" prop="conSignTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.conSignTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择合同签订时间，">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同录入时间，" prop="conInfoTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.conInfoTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择合同录入时间，">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同审核时间，" prop="conAudTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.conAudTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择合同审核时间，">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同录入人" prop="operId">
          <el-input v-model="form.operId" placeholder="请输入合同录入人" />
        </el-form-item>
        <el-form-item label="收房人，" prop="sfUserId">
          <el-input v-model="form.sfUserId" placeholder="请输入收房人，" />
        </el-form-item>
        <el-form-item label="收房人姓名" prop="sfUserName">
          <el-input v-model="form.sfUserName" placeholder="请输入收房人姓名" />
        </el-form-item>
        <el-form-item label="合同状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="续约状态">
          <el-radio-group v-model="form.xyStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否收房贷,0:否 1:是" prop="sfLoanFlg">
          <el-input v-model="form.sfLoanFlg" placeholder="请输入是否收房贷,0:否 1:是" />
        </el-form-item>
        <el-form-item label="冻结状态：0未冻结 1已冻结(申请金融服务的时候，才会有冻结状态)">
          <el-radio-group v-model="form.freezeStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="银行账户类型" prop="accountType">
          <el-select v-model="form.accountType" placeholder="请选择银行账户类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="账户名称" prop="accountName">
          <el-input v-model="form.accountName" placeholder="请输入账户名称" />
        </el-form-item>
        <el-form-item label="联行行号" prop="bankBranchCodeLh">
          <el-input v-model="form.bankBranchCodeLh" placeholder="请输入联行行号" />
        </el-form-item>
        <el-form-item label="开户行所在省ID" prop="bankAccountProvince">
          <el-input v-model="form.bankAccountProvince" placeholder="请输入开户行所在省ID" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserve1">
          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserve2">
          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserve3">
          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserve4">
          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserve5">
          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />
        </el-form-item>
        <el-form-item label="删除标识，0:未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识，0:未删除，1：删除" />
        </el-form-item>
        <el-form-item label="创建用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />
        </el-form-item>
        <el-form-item label="房产类型：1.合租；2.整租；3.公寓" prop="houseLeaseType">
          <el-select v-model="form.houseLeaseType" placeholder="请选择房产类型：1.合租；2.整租；3.公寓">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContract, getContract, delContract, addContract, updateContract } from "@/api/system/contract";

export default {
  name: "Contract",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      contractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sfContractNo: null,
        outContractNo: null,
        lastContractId: null,
        lastContractNo: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        premiseName: null,
        houseId: null,
        houseName: null,
        houseType: null,
        houseZsNo: null,
        cqAddress: null,
        ownerId: null,
        ownerName: null,
        signWithOwner: null,
        ownerIdCard: null,
        ownerMobile: null,
        ownerContactAddress: null,
        signUserName: null,
        signUserIdCard: null,
        signUserMobile: null,
        signUserEmergencyPhone: null,
        bankCard: null,
        bankUserName: null,
        bankUserIdCard: null,
        bankId: null,
        bankName: null,
        bankOpen: null,
        leaseStartTime: null,
        leaseEndTime: null,
        monthRent: null,
        depositMoney: null,
        depositType: null,
        paymentType: null,
        conSignTime: null,
        conInfoTime: null,
        conAudTime: null,
        operId: null,
        sfUserId: null,
        sfUserName: null,
        status: null,
        xyStatus: null,
        sfLoanFlg: null,
        freezeStatus: null,
        accountType: null,
        bankCardNumber: null,
        accountName: null,
        bankBranchCodeLh: null,
        bankAccountProvince: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
        houseLeaseType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sfContractNo: [
          { required: true, message: "合同编号不能为空", trigger: "blur" }
        ],
        businessId: [
          { required: true, message: "商户ID不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "部门ID不能为空", trigger: "blur" }
        ],
        deptNo: [
          { required: true, message: "部门编号不能为空", trigger: "blur" }
        ],
        premiseName: [
          { required: true, message: "小区名(使用楼盘名称)不能为空", trigger: "blur" }
        ],
        houseId: [
          { required: true, message: "房产编号不能为空", trigger: "blur" }
        ],
        houseName: [
          { required: true, message: "房产信息(考虑在房产表中增加house_name，然后带出)不能为空", trigger: "blur" }
        ],
        houseType: [
          { required: true, message: "所有权类型(1：国有房产，2：直管房产，3：自管房产，4：军队房产，5：集体所有房产，6：私有(自由)房产，7：港、澳、台投资房产，8：涉外房产，9：其它房产)不能为空", trigger: "change" }
        ],
        ownerId: [
          { required: true, message: "业主ID不能为空", trigger: "blur" }
        ],
        ownerName: [
          { required: true, message: "业主姓名不能为空", trigger: "blur" }
        ],
        signWithOwner: [
          { required: true, message: "是否为签约人不能为空", trigger: "blur" }
        ],
        signUserName: [
          { required: true, message: "签约人(甲方)不能为空", trigger: "blur" }
        ],
        bankCard: [
          { required: true, message: "银行卡号不能为空", trigger: "blur" }
        ],
        leaseStartTime: [
          { required: true, message: "租约期限开始时间不能为空", trigger: "blur" }
        ],
        leaseEndTime: [
          { required: true, message: "租约期限结束时间不能为空", trigger: "blur" }
        ],
        monthRent: [
          { required: true, message: "收房月租金不能为空", trigger: "blur" }
        ],
        depositType: [
          { required: true, message: "支付方式(押X付Y的X)不能为空", trigger: "change" }
        ],
        paymentType: [
          { required: true, message: "支付方式(押X付Y的Y）不能为空", trigger: "change" }
        ],
        operId: [
          { required: true, message: "合同录入人不能为空", trigger: "blur" }
        ],
        sfUserId: [
          { required: true, message: "收房人，不能为空", trigger: "blur" }
        ],
        sfUserName: [
          { required: true, message: "收房人姓名不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "合同状态不能为空", trigger: "blur" }
        ],
        xyStatus: [
          { required: true, message: "续约状态不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识，0:未删除，1：删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sfContractNo: null,
        outContractNo: null,
        lastContractId: null,
        lastContractNo: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        premiseName: null,
        houseId: null,
        houseName: null,
        houseType: null,
        houseZsNo: null,
        cqAddress: null,
        ownerId: null,
        ownerName: null,
        signWithOwner: null,
        ownerIdCard: null,
        ownerMobile: null,
        ownerContactAddress: null,
        signUserName: null,
        signUserIdCard: null,
        signUserMobile: null,
        signUserEmergencyPhone: null,
        bankCard: null,
        bankUserName: null,
        bankUserIdCard: null,
        bankId: null,
        bankName: null,
        bankOpen: null,
        leaseStartTime: null,
        leaseEndTime: null,
        monthRent: null,
        depositMoney: null,
        depositType: null,
        paymentType: null,
        conSignTime: null,
        conInfoTime: null,
        conAudTime: null,
        operId: null,
        sfUserId: null,
        sfUserName: null,
        status: 0,
        xyStatus: 0,
        sfLoanFlg: null,
        freezeStatus: 0,
        accountType: null,
        bankCardNumber: null,
        accountName: null,
        bankBranchCodeLh: null,
        bankAccountProvince: null,
        remark: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null,
        houseLeaseType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /**多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContract(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContract(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addContract(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delContract(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contract/export', {
        ...this.queryParams
      }, `system_contract.xlsx`)
    }
  }
};
</script>
